package org.squabble.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.squabble.domain.Privilege;

@Repository
public class PrivilegeDAOImpl extends AbstractHibernateDAO<Privilege> implements
		PrivilegeDAO {

	@Autowired
	public PrivilegeDAOImpl(SessionFactory sessionFactory) {
		super(Privilege.class, sessionFactory);
	}

	@Override
	public Privilege getPrivilege(Long id) {
		return get(id);
	}

	@Override
	public Privilege getPrivilege(String name) {
		return uniqueResult(criteria().add(Restrictions.ilike("name", name)));
	}

	@Override
	public List<Privilege> getPrivileges() {
		return list(criteria().addOrder(Order.asc("name")));
	}
}
